﻿
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LPY.LeHealth.DTO;
using LPY.LeHealth.Service;
using System.Web.Mvc;
using System;
using LPY.LeHealth.Model;
using LPY.LeHealth.DAL;

namespace LPY.LeHealth.WebSite.Controllers
{

    public class AppController:Controller
    {
        private AppService appserver;

        private LPY.LeHealth.Service.AppImageService appImageService;

        public AppController()
        {
            appserver = new AppService();

            appImageService = new AppImageService();
        }

        /// <summary>
        /// 显示评论消息
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        public JsonResult showapp()
        {
            
            Common.JsonMessage jm = new Common.JsonMessage();
            jm.Data = appserver.getapp().ToList();
            return Json(jm, JsonRequestBehavior.AllowGet);
        }

        
        /// <summary>
        ///显示全部信息
        /// </summary>
        /// <returns></returns>
       [HttpGet]
        public JsonResult showappall()
        {
            List<AppModel> list = appserver.getappall();
            return Json(list,JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        public JsonResult plshow()
        {
            int uid =Convert.ToInt32(Session["useid"]);
            List<AppModel> list = appserver.plshow(uid);
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public JsonResult plshowwei()
        {
            int uid = Convert.ToInt32(Session["useid"]);
            List<AppModel> list = appserver.plshowwei(uid);
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 获取图片信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetImage()
        {
            Common.JsonMessage jm = new Common.JsonMessage();
            List<AppImage> list = appImageService.GetTop5();
            if(list.Count>0)
            {jm.Code = 1;
            jm.Msg = "获取地址成功";
            jm.Data = list;
            }
            else
            {
                jm.Code = 0;
                jm.Msg = "无数据";
            }


            return Json(jm, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 显示地区表信息
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        public JsonResult showcity()
        {
            List<City> list = appserver.GetAll();
            return Json(list, JsonRequestBehavior.AllowGet);

        }
        /// <summary>
        /// 显示地区表信息
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        public JsonResult showcityTop7()
        {
            List<City> list = appserver.GetTop7();
            return Json(list, JsonRequestBehavior.AllowGet);

        }

        /// <summary>
        /// 获取全局地区id
        /// </summary>
        /// <param name="diquid"></param>
        /// <returns></returns>
        public ActionResult getid(int diquid)
        {
            Session["cityid"] = diquid;
            Session["cityname"] = appserver.getName(diquid);

            return View();
        }
    }
}